Repository navigation
Abort in my_malloc() when an allocation fails - #417
Open
suraiya-ctrl wants to merge 1 commit into
Open
suraiya-ctrl wants to merge 1 commit into
suraiya-ctrl wants to merge 1 commit into
Conversation
kalvdans
reviewed
Nov 17, 2026
kalvdans
left a comment
Contributor
There was a problem hiding this comment.
Thanks! I think a better change is to abort() the program in my_malloc() if an allocation fails.
The scratch buffers in blosc_getitem(), serial_blosc(), t_blosc() and init_threads() are sized from the blocksize in the compressed header and none of them check the result, so a failed allocation left tmp NULL and tmp2/tmp3 at NULL + blocksize, and blosc_d() then wrote decompressed bytes to an address picked by the header. Callers cannot do anything useful with a NULL here, so fail loudly in my_malloc() instead. The message now goes to stderr, which is unbuffered and therefore still reaches the user after the abort().
suraiya-ctrl
force-pushed
the
check-scratch-alloc
branch
from
November 26, 2026 07:16
0d2aca2 to
5d69e3d
Compare
Contributor
Author
|
Makes sense, that's simpler. Switched to I also dropped the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
my_malloc()'s callers inblosc_getitem(),serial_blosc(),t_blosc()andinit_threads()size the scratch buffers from the blocksize in the compressed header (up toBLOSC_MAX_BLOCKSIZE, so roughly 2.1 GB of scratch) and none of them check the result. On a failed allocationtmpwas NULL andtmp2/tmp3were NULL + blocksize, soblosc_d()wrote decompressed bytes to an address picked by the header.Per review this now aborts in
my_malloc()instead of threading a check through every call site. The message moved to stderr, which is unbuffered and so still reaches the user after theabort().Repro: a 64-byte buffer with version 2, blosclz, flags 0x10, typesize 1, nbytes = blocksize =
BLOSC_MAX_BLOCKSIZE, cbytes 64, bstarts[0] = 20, split cbytes 40, then 40 bytes of 0x41, passed toblosc_getitem(buf, 0, 1, out)in an ASan build underallocator_may_return_null=1:max_allocation_size_mb=1000. Before: SEGV WRITE at 0x2aaaa956 in blosclz_decompress <- blosc_d <- blosc_getitem. Now: SIGABRT with the message. The same buffer throughblosc_decompress()behaves the same way. All 1646 ctest cases pass.